package com.gnerv.sylvanas.business.manage.operation;

import com.gnerv.sylvanas.framework.core.BaseCurrentAccount;
import com.gnerv.sylvanas.business.manage.model.bo.RoleBO;
import com.gnerv.sylvanas.business.manage.model.dto.RoleDTO;
import com.gnerv.sylvanas.business.manage.model.entity.Role;
import com.gnerv.sylvanas.business.manage.storage.RoleStorageService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

/**
 * @author Gnerv LiGen
 */
@Service
@AllArgsConstructor
public class RoleOperationService {

    private final RoleStorageService roleStorageService;
    private final BaseCurrentAccount baseCurrentAccount;

    
    public boolean create(RoleBO roleBO) {
        Role role = roleBO.toRole();
        
        roleStorageService.insert(role);
        return true;
    }

    
    public boolean deleteByUkId(String ukId) {
        roleStorageService.deleteByUkId(ukId);
        return true;
    }

    
    public boolean updateByUkId(RoleBO roleBO) {
        Role role = roleBO.toRole();
        roleStorageService.updateByUkId(role);
        return true;
    }

    
    public RoleDTO selectByUkId(String ukId) {
        return roleStorageService.selectByUkId(ukId);
    }

    
    public List<RoleDTO> selectListByName(String name) {
        return roleStorageService.selectListByName(name);
    }

    
    public List<String> selectListUkIdByAccountUkId(String accountUkId) {
        return roleStorageService.selectListUkIdByAccountUkId(accountUkId);
    }

    
    public boolean bindAccount(String roleUkId, Set<String> accountUkIdList) {
        roleStorageService.bindAccount(roleUkId, accountUkIdList, baseCurrentAccount.ukId());
        return true;
    }

    
    public boolean bindApi(String roleUkId, Set<String> permissionUkIdList) {
        roleStorageService.bindApi(roleUkId, permissionUkIdList, baseCurrentAccount.ukId());
        return true;
    }

    
    public boolean bindView(String roleUkId, Set<String> viewUkIdList) {
        roleStorageService.bindView(roleUkId, viewUkIdList, baseCurrentAccount.ukId());
        return true;
    }

    
    public boolean unbindAccount(String roleUkId) {
        roleStorageService.unbindAccount(roleUkId);
        return true;
    }

    
    public boolean unbindApi(String roleUkId) {
        roleStorageService.unbindApi(roleUkId);
        return true;
    }

    
    public boolean unbindView(String roleUkId) {
        roleStorageService.unbindView(roleUkId);
        return true;
    }
}




